/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.ex;

import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>Project: javase2203 - Ex2
 * <p>Powered by webrx On 2022-08-15 09:23:28
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex2 {
    public static void main(String[] args) {
        try (var in = new FileInputStream("user.txt")) {
            String str = new String(in.readAllBytes());
            Pattern p = Pattern.compile("[a-z]+", Pattern.CASE_INSENSITIVE);
            Matcher m = p.matcher(str);
            Map<String, Integer> map = new HashMap<>();
            while (m.find()) {
                String tt = m.group().toLowerCase();
                if (map.containsKey(tt)) {
                    map.put(tt, map.get(tt) + 1);

                } else {
                    map.put(tt, 1);
                }
            }

            System.out.println(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
